#ifndef	__ZEALINK_JOB_CONTROL_LIST__
#define	__ZEALINK_JOB_CONTROL_LIST__
#include "threadlock.h"
/////////////////////////////////////////////////////////////////////////////

class NOVTABLE job_list
{
public:
	threadlock::multi_threaded_local m_lock;
#define   _autogard() threadlock::autoguard<threadlock::multi_threaded_local>  xxx(&m_lock)
	zwl_srv_control*get(void)
	{
		zwl_srv_control*pcontrol=NULL;
		//EnterCriticalSection(&__cs__);
		_autogard();
		if(__list__)
		{
			pcontrol = __list__;
			__list__ = __list__->_pnext;
			if(!__list__) __end__ = NULL;
			pcontrol->_pnext = NULL;
		}
		//LeaveCriticalSection(&__cs__);
		Sleep(1);
		return(pcontrol);
	}
	void add_job(zwl_srv_control*pcontrol)
	{
		pcontrol->_pnext = NULL;
		//EnterCriticalSection(&__cs__);
		_autogard();
		(__end__?__end__->_pnext:__list__) = pcontrol;
		__end__ = pcontrol;
		//LeaveCriticalSection(&__cs__);
	}
	void destory(void)
	{
		zwl_srv_control*pnext=NULL;
		//EnterCriticalSection(&__cs__);
		_autogard();
		for(;__list__;__list__=pnext)
		{
			pnext = __list__->_pnext;
			delete __list__;
		}
		//LeaveCriticalSection(&__cs__);
	}
	job_list(void):__list__(NULL),__end__(NULL)
	{
		//InitializeCriticalSection(&__cs__);
	}
	~job_list(void)
	{
		//DeleteCriticalSection(&__cs__);
	}
	zwl_srv_control *__list__,*__end__;
	//CRITICAL_SECTION __cs__;
};
/////////////////////////////////////////////////////////////////////////////
#endif
